package com.lagou.service.impl;/**
 * Created by IntelliJ IDEA.
 * User: Yangdx.
 * Date: 2020/7/26.
 * Time: 1:00.
 * Tags: Code, we are serious.
 */

import com.lagou.model.EmailService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

/**
 * @author
 * @create 2020-07-26 1:00
 **/
@Service
@RefreshScope
public class EmailServiceImpl implements EmailService {
    @Autowired
    private JavaMailSender mailSender;
    @Value("${config.email.sender.name}")
    private String from;
    @Override
    public boolean sendEmail(String mailTo, String mailTitle, String message) {
        try {
            //创建SimpleMailMessage对象
            SimpleMailMessage mailMessage = new SimpleMailMessage();
            //邮件发送人
            mailMessage.setFrom(from);
            //邮件接收人
            mailMessage.setTo(mailTitle);
            //邮件主题
            mailMessage.setSubject("验证码");
            //邮件内容
            mailMessage.setText(message);
            //发送邮件
            mailSender.send(mailMessage);
            return true;
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }
    }
}
